# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=jimtcl
pkgver=0.81
pkgrel=0
pkgdesc="An open-source, small footprint implementation of Tcl"
url="https://github.com/msteveb/jimtcl"
arch="all"
license="BSD-2-Clause"
depends_dev="openssl1.1-compat-dev"
makedepends="
	$depends_dev
	libexecinfo-dev
	readline-dev
	sqlite-dev
	tcl
	zlib-dev
	"
options="net"  # fix check with abuild rootbld
subpackages="$pkgname-dbg $pkgname-readline $pkgname-sqlite3 $pkgname-dev $pkgname-doc"
source="https://github.com/msteveb/jimtcl/archive/$pkgver/jimtcl-$pkgver.tar.gz
	tests-skip-exec2-3.2.patch
	tests-skip-socket.patch
	"

prepare() {
	default_prepare

	# tty tests fail on builders - no tty available there.
	rm tests/tty.test

	cp -r "$builddir" "$builddir-static"
}

build() {
	_build --shared

	cd "$builddir-static"
	_build
}

_build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--docdir=/usr/share/doc/$pkgname \
		--full \
		--with-mod=sqlite3,readline,rlprompt \
		"$@"
	make -j1
}

check() {
	make check
}

package() {
	make install DESTDIR="$pkgdir"
	ln -s /usr/lib/libjim.so.$pkgver "$pkgdir"/usr/lib/libjim.so

	install -m644 "$builddir-static"/libjim.a -t "$pkgdir"/usr/lib/
}

readline() {
	pkgdesc="Interface to readline and Tcl wrapper for Jim Tcl"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/jim/readline.so
	amove usr/lib/jim/rlprompt.tcl
}

sqlite3() {
	pkgdesc="Interface to sqlite3 for Jim Tcl"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/jim/sqlite3.so
}

dev() {
	default_dev
	amove usr/bin/build-jim-ext
}

sha512sums="
5f798b15fd32673e2e2769e25c4dfeee43696e5bbd2d3ec3fd2f312fa49da9ef057fb4de81a10d3812dc07fb2e40ed79924b024e537e064d3213b10e06a416b6  jimtcl-0.81.tar.gz
09afa356d5b8330bbb4444c319edb4fb4caae18747b924a3cb82cd7d9062566b6180b05e4938b9e33c3bf76acf2b28a9dbdedc10b9c241dcb99ff07828c4f507  tests-skip-exec2-3.2.patch
cbc3f08d23cfe7ebd45e677a09e7178436e728a965ab7af44d6e27621049c1cdc82768c4e81397004be3486bf3f767684601ec28d3584ea14d3dde69ccdd8bdb  tests-skip-socket.patch
"
